//
//  PassMapValue.m
//  easyTaxi
//
//  Created by ellenpage on 12-12-24.
//  Copyright (c) 2012年 ellenpage. All rights reserved.
//

#import "Constant.h"
#import "PassMapValue.h"
#import "PassValueClass.h"

@implementation PassMapValue

static PassMapValue *sharedPassMapValueClass = nil;

+ (PassMapValue *)sharedIntance
{
    @synchronized(self)
    {
        if (sharedPassMapValueClass == nil)
        {
            sharedPassMapValueClass = [[PassMapValue alloc] init];
        }
    }
    return  sharedPassMapValueClass;
}

- (id)init
{
    if (self = [super init])
    {
        self.mapView     = [[BMKMapView alloc] init];
        self.driverPoint = [[BMKPointAnnotation alloc] init];
        self.driverPoint.title = @"接单的司机";
    }
    return self;
}

- (void)uploadDriverPosition:(CLLocationCoordinate2D)cor2d
{
    [_mapView removeAnnotation:_driverPoint];
    _driverPoint.coordinate = cor2d;
    [_mapView addAnnotation:_driverPoint];
    [_mapView selectAnnotation:_driverPoint animated:YES];
}

- (void)showDrivers
{
    NSArray *array = [PassValueClass sharedIntance].nearDriversArrsy;
    for (int i = 0; i < array.count; i++)
    {
        NSDictionary *dict = [array objectAtIndex:i];
        
        CLLocationCoordinate2D driverCo;
        NSString *lngStr   = [dict objectForKey:kLongitude];
        NSString *latStr   = [dict objectForKey:kLatitude];
        driverCo.latitude  = [latStr floatValue];
        driverCo.longitude = [lngStr floatValue];
        
        BMKPointAnnotation *driverPoint = [[BMKPointAnnotation alloc] init];
        driverPoint.coordinate = driverCo;
        
        NSString *tagStr       = [NSString stringWithFormat:@"%d",i+1];
        NSString *carStatusStr = [dict objectForKey:kStatus];
        
        if (carStatusStr.length == 1)
        {
            if ([carStatusStr isEqualToString:@"1"])
            {
                driverPoint.title = @"空车司机";
                driverPoint.subtitle = tagStr;
                [_mapView selectAnnotation:driverPoint animated:YES];
            }
            else if ([carStatusStr isEqualToString:@"2"])
            {
                driverPoint.title = @"载客司机";
                driverPoint.subtitle = tagStr;
                [_mapView selectAnnotation:driverPoint animated:YES];
            }
            else if ([carStatusStr isEqualToString:@"3"])
            {
                driverPoint.title = @"司机";
                driverPoint.subtitle = tagStr;
                [_mapView selectAnnotation:driverPoint animated:YES];
            }
        }
        
        [_mapView addAnnotation:driverPoint];
    }
}

- (void)showDriverFromTianZe:(float)lat lng:(float)lng
{
    CLLocationCoordinate2D driverCo;
    driverCo.latitude  = lat;
    driverCo.longitude = lng;

    BMKPointAnnotation *driverPoint = [[BMKPointAnnotation alloc] init];
    driverPoint.coordinate = driverCo;
    
    driverPoint.title = @"接单司机";
    [_mapView selectAnnotation:driverPoint animated:YES];
    
    [_mapView addAnnotation:driverPoint];
}
@end
